import ast
import requests
import json

# 得到登录得到的token
cmd = "python 1_红人点集登录.py"
pro = subprocess.run(cmd, stdout=subprocess.PIPE)
_token = pro.stdout
token = _token.decode().strip()
token_1 = ast.literal_eval(token)
token_r = token_1["data"]["token"]
phoneNum = token_1["data"]["nickname"]
cmd2 = f"node 2_红人点集sign加密.js"
pro2 = subprocess.run(cmd2, stdout=subprocess.PIPE)
_sign = pro2.stdout
sign = _sign.decode().strip().split("\n")

url = "https://api.hrdatayun.com:60358/api/ks"
headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Type': 'application/json;charset=UTF-8',
    'Host': 'api.hrdatayun.com:60358',
    'Origin': 'http://www.hrdatayun.com',
    'Referer': 'http://www.hrdatayun.com/',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
}
params = "{\"no\":\"ks0400\",\"data\":{\"page_num\":\"1\",\"hours\":\"\",\"days\":\"\",\"page_size\":\"50\"}}"
data = {
    'param': params,
    'sign': sign[0],
    'tenant': "1",
    'timestamp': sign[1],
    'token': token_r
}
session = requests.session()
session.headers = headers

response = session.post(url=url,data=json.dumps(data))
if (response.status_code == 200):
    print(response.json())
else:
    print(response.status_code)
